// JavaScript Document
define(function (require, exports, module) {
	var Masker=require("Masker");


	PreviewFrameWindow=function(){
		/*if(typeof(selector)=="undefined"){
			this.create()
		}else{
			this.element=$(selector).get(0)
		}*/
		var self=this;
	}
	PreviewFrameWindow.prototype.opened=false;
	PreviewFrameWindow.prototype.create=function(){

		var self=this;
		this.element=document.createElement("div");
		this.element.className="ht_window previewFrameWindow close";
		
		

		this.element.style.display="none"
		
		
		
		
		this.wrapper=document.createElement("div");
		this.wrapper.className="wrapper"
		this.title=document.createElement("h4");
		this.title.className="title"
		this.title.innerHTML="详细"
		
		
		this.closeButton=document.createElement("input")
		this.closeButton.type="button"
		this.closeButton.className="closeButton"
		this.closeButton.value="关闭"
		
		/*
		ie 7iframe　name 会被变成 submitName !!!!!!!!
		this.iframe=document.createElement("iframe")
		this.iframe.frameBorder=0;
		this.iframe.scrolling="yes";
		this.iframe.name="submitWindowFrame"
		*/
		this.iframe=$("<iframe scrolling=\"yes\" frameborder=\"0\" name=\"previewWindowFrame\"></iframe>").get(0);
		
		this.element.appendChild(this.wrapper)
		this.wrapper.appendChild(this.title)
		this.wrapper.appendChild(this.closeButton)
		this.wrapper.appendChild(this.iframe)
		
		document.body.appendChild(this.element)
		$(this.element).find("[class=closeButton]").bind("click",function(event){self.closeButtonClickHandler(event)})
		
		
	}
	
	
	
	
	PreviewFrameWindow.prototype.closeButtonClickHandler=function(event){
		this.close();
	}
	PreviewFrameWindow.prototype.close=function(){
		if(this.opened==false){
			return false;
		}
		this.element.className="ht_window previewFrameWindow close"
		this.masker.close()
		var self=this;
		//self.remove();
		this.wrapper.removeChild(this.iframe)
		var timer=setTimeout(function(){
			self.remove();
		},500);
		this.iframe.src="";
		//this.wrapper.removeChild(this.iframe)
		//$(this.element).animate({opacity:'0'},"fast");
		//document.body.removeChild(this.element)
		this.opened=false;
		
		

	}
	PreviewFrameWindow.prototype.open=function(title,src,launchParentWindow){
		/*if(src.indexOf("%7B")!="-1"){
			return false;
		}*/
		
		var self=this;
		this.masker=new Masker();
		this.masker.open()
		
		this.create();
		
		
		
		this.title.innerHTML=title;
		this.launchParentWindow=launchParentWindow;
		self.element.style.display="block"
		setTimeout(function(){
			self.element.className="ht_window previewFrameWindow open"
			self.opened=true;
		},0)
		return this;
	}
	
	PreviewFrameWindow.prototype.remove=function(){
		//this.element.style.display="none"
		this.element.parentNode.removeChild(this.element)
		//document.body.removeChild(this.element)
	}
	module.exports = PreviewFrameWindow;
});